<style>
  .el-input-number.is-without-controls .el-input__inner {
    width: 180px;
    line-height: 30px;
    height: 28px;
  }
</style>
<template>
  <div class="login">
    <el-form ref="loginForm" :model="loginForm" :rules="loginRules" class="login-form">
      <h3 class="title">vue2-admin-fast</h3>
      <el-form-item prop="account">
        <el-input v-model="loginForm.mobile" type="text" auto-complete="off" placeholder="mobile ">
          <svg-icon slot="prefix" icon-class="user" class="el-input__icon input-icon" />
        </el-input>
      </el-form-item>
      <el-form-item prop="password">
        <el-input
                ref="password"
                v-model="loginForm.password"
                :type="passwordType"
                auto-complete="off"
                placeholder="password"
                @keyup.enter.native="handleLogin"
        >
          <svg-icon slot="prefix" icon-class="password" class="el-input__icon input-icon" />
        </el-input>
        <span class="show-pwd" @click="showPwd">
            <svg-icon :icon-class="passwordType === 'password' ? 'eye' : 'eye-open'" />
          </span>
      </el-form-item>
      <jcRange :successFun="onMpanelSuccess" :errorFun="onMpanelError"></jcRange>
      <el-form-item style="width:100%;margin-top: 15px">
        <el-button
                :loading="loading"
                size="medium"
                type="primary"
                style="width:100%;"
                @click.native.prevent="handleLogin"
        >
          <span v-if="!loading">LOGIN</span>
          <span v-else>LOGINING...</span>
        </el-button>
      </el-form-item>
    </el-form>
    <!--  底部  -->
    <div class="el-login-footer">
      <span>Copyright © 2021 wxb666</span>
    </div>
  </div>
</template>

<script>
import jcRange from '@/components/JcRange'

    export default {
        name: "Login",
        components: {
            jcRange
        },
        data() {
            return {
                num:'',
                cookiePassword: "",
                loginForm: {
                    mobile: "admin",
                    password: "123456",
                },
                loginRules: {
                    mobile: [
                        { required: true, trigger: "blur", message: "can't be empty" }
                    ],
                    password: [
                        { required: true, trigger: "blur", message: "can't be empty" }
                    ]
                },
                passwordType: 'password',
                loading: false,
                redirect: undefined,
                slideVerify: false,
            };
        },
        watch: {
            $route: {
                handler: function(route) {
                    this.redirect = route.query && route.query.redirect;
                },
                immediate: true
            }
        },
        created() {
        },
        methods: {
            /** 登录 */
            handleLogin() {
                this.$refs.loginForm.validate(async valid => {
                    if (!this.slideVerify) {
                        this.$modal.msg('请先进行人工验证！')
                        return
                    }
                    if (valid) {
                        this.loading = true;
                        /** login */
                        try {
                            // localStorage.setItem('lang','cn')
                            window.location.reload()
                            this.$store.commit('SET_TOKEN', 'wxb')
                            this.$router.push({ path: this.redirect || "/" });
                        } catch (e) {
                            this.loading = false
                        }
                    }
                });
            },
            /** 显示、隐藏密码 */
            showPwd() {
                if (this.passwordType === 'password') {
                    this.passwordType = ''
                } else {
                    this.passwordType = 'password'
                }
                this.$nextTick(() => {
                    this.$refs.password.focus()
                })
            },

            /* 滑块验证成功 */
            onMpanelSuccess () {
                this.slideVerify = true;
            },

            /* 滑块验证失败 */
            onMpanelError () {
                this.slideVerify = false;
            },
        }
    };
</script>

<style lang="less" scoped>
@import "index.less";
</style>
